/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once


#include <场景/intern/S_Scene.h>


void		f_scene_创建环境();
void		f_scene_销毁环境();
S_Scene*	f_scene_创建场景(uint32 key);
//bool		f_场景是否存在(uint32 key);
void		f_scene_销毁(uint32 key);

S_Scene*	f_scene_get场景(uint32 key);

void		f_scene_渲染(S_Scene* scene);


void f_scene_添加物体列表(S_Scene* scene, S_物体* ob);

void		f_scene_场景链接物体(uint32 sceneID, uint32 objectID);
void		f_scene_场景链接物体(S_Scene* scene, S_物体* object);
void		f_scene_开启光追(S_Scene* scene, S_设备环境& ctx);
void        f_scene_销毁光追渲染器(S_Scene* scene);
void		f_scene_重构光追线管(S_Scene* scene, S_设备环境& ctx);
void		f_scene_添加光追材质着色器(S_Scene* scene, const std::string path, int32 loc);
void		f_scene_删除光追材质着色器(S_Scene* scene, int32 loc);
void		f_scene_重建着色器();
void        f_scene_更新物体渲染(S_Scene* scene, S_物体* object);
void		f_scene_构建顶层光追加速结构(S_Scene* scene, S_OBArray* obs, S_设备环境& ctx);

void	f_scene_设置光追渲染采样(S_Scene* scene, S_RayRenderAttr& Attr);
//void	f_scene_设置光追渲染子采样(S_Scene* scene, uint32 子采样);
void	f_scene_设置环境着色器(S_Scene* scene, int32 环境着色器ID);
void	f_scene_设置光追渲染器渲染(S_Scene* scene, bool 是否渲染);
void	f_scene_往渲染器里添加纹理(const S_纹理添加列队& 纹理加载信息);
void	f_scene_从渲染器里移除纹理(const S_纹理添加列队& 纹理移除信息);

S_纹理* f_scene_创建纹理(S_Scene* scene, S_设备环境& ctx, std::wstring name);
bool    f_scene_销毁纹理(S_Scene* scene, S_纹理* tex);
bool    f_scene_销毁渲染器纹理(S_Scene* scene, uint32 保留数量);
void    f_scene_重载渲染器绑定纹理(S_Scene* scene, S_纹理* tex);



void		f_连接物理引擎车辆操控函数(S_Scene* scene, fun_物体async_p f);
void		f_连接渲染前更新函数(S_Scene* scene, fun_渲染前更新p f);


车辆容器_t	f_get场景中车辆(S_Scene* scene);



std::vector<S_物体*> f_scene_射线拾取(S_Scene* scene, const vec3& s, const vec3& e, float32* 最近坐标 = nullptr);
void                 f_scene_框选物体(S_物体* 待选物体, std::vector<S_物体*>& 选择物体, const vec4 平面[5]);
//int32					f_scene_射线拾取物体线(S_物体* ob, const vec3& s, const vec3& e, float32 最大距离);



S_实例拾取信息	f_scene_射线拾取物体实例(S_物体* ob, const vec3& s, const vec3& e);


void	f_scene_渲染器GPU内存映射();
void	f_scene_渲染器GPU内存解映射();
void	f_scene_渲染器分配GPU内存();
void    f_scene_物体GPU内存分配();


uint32	f_scene_渲染器分配平行光内存(S_Scene* scene, uint32 num = 1);
uint32	f_scene_渲染器分配点光源内存(S_Scene* scene, uint32 num = 1);
uint32	f_scene_渲染器分配区域光内存(S_Scene* scene, uint32 num = 1);
uint32	f_scene_渲染器分配聚光灯内存(S_Scene* scene, uint32 num = 1);

void	f_scene_渲染器设置平行光(S_Scene* scene, uint32 ID, const S_LigthParallel& ligth);
void	f_scene_渲染器设置平行光启用(S_Scene* scene, uint32 ID, const bool e);
void	f_scene_渲染器设置点光源(S_Scene* scene, uint32 ID, const S_LigthPoint& ligth);
void	f_scene_渲染器设置点光源启用(S_Scene* scene, uint32 ID, const bool e);
void	f_scene_渲染器设置聚光灯(S_Scene* scene, uint32 ID, const S_LigthSpot& ligth);
void	f_scene_渲染器设置聚光灯启用(S_Scene* scene, uint32 ID, const bool e);
void	f_scene_渲染器设置区域光(S_Scene* scene, uint32 ID, const S_LigthArea& ligth);
void	f_scene_渲染器设置区域光启用(S_Scene* scene, uint32 ID, const bool e);

void    f_render_刷新渲染(S_Scene* scene);
